<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
if(isset($_GET["field"])){
    if($_GET["field"]==""){
        echo "false";
        exit;
    }
    $id=intval($_GET["id"]);
    $field=trim($_GET["catdir"]);
    if($id>0){
        $row=$ezhand->select(MOD,'*','catdir="'.$field.'" and id<>"'.$id.'"');
    }else{
        $row=$ezhand->select(MOD,'*','catdir="'.$field.'"');
    
    }
    if(empty($row)){
        echo "true";
        exit;        
    }else{
        echo "false";
        exit;        
    }
    
}

if($_POST['sub']!=''){
    $id=empty($_POST['id'])?0:(int)$_POST['id'];
	unset($_POST['id']);
	unset($_POST['sub']);
	$data=array('parentid'=>trim($_POST["parentid"]),'name'=>trim($_POST["catname"]),
    'meta_description'=>trim($_POST["meta_description"])
    
    
    );
    $data["level"]=0;
    if($_POST["parentid"]>0){
        $data["level"]=$ezhand->get_cat_level($_POST["parentid"],0,"shopping3_category");
    }
    
    if(trim($_POST['catname'])==""){
        jumpajax('300','栏目名称不能为空!','');
    }
    $catdir=trim($_POST["catdir"]);
 	if($id==0){
        $id=$ezhand->insert("shopping3_category",$data);
		jumpajax('200','保存成功','','closeCurrent');
	}else{
	    $ezhand->update("shopping3_category",$data,'id="'.$id.'"');
		jumpajax('200','修改成功','','closeCurrent');
	}
}
else{
	$id=empty($_GET['id'])?0:(int)$_GET['id'];
    
    $parentid=empty($_GET['parentid'])?0:(int)$_GET['parentid'];
    
    
    
    $catlist[0]="作为一级分类";
    $catlisttemp=$ezhand->get_cattree2(0,"shopping3_category");
  
    
    if($id==0){
	    $row=array();
        $row["parentid"]=$parentid;
	}else{
	   
	    $row=$ezhand->select("shopping3_category",'*','id="'.$id.'"');
	}
}
?>